<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of GEplot_3D</title>
  <meta name="keywords" content="GEplot_3D">
  <meta name="description" content="">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html trunk --><!-- menu.html utils -->
<h1>GEplot_3D
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong></strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function GEplot_3D(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">
3D adaptation of GEplot.  3D version will plot a 3 dimensional plot given the added elevation vector
input--P.R. Jackson, USGS, 1-16-08</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function GEplot_3D(filename,Lat,Lon,Elev,style,opt11,opt12,opt21,opt22)</a>
0002 <span class="comment">%</span>
0003 <span class="comment">%3D adaptation of GEplot.  3D version will plot a 3 dimensional plot given the added elevation vector</span>
0004 <span class="comment">%input--P.R. Jackson, USGS, 1-16-08</span>
0005 
0006 <span class="comment">% function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22)</span>
0007 <span class="comment">%</span>
0008 <span class="comment">% Description: creates a file in kmz format that can be opened into Google Earth.</span>
0009 <span class="comment">%    GEplot uses the same syntax as the traditional plot function but</span>
0010 <span class="comment">%    requires Latitude and Longitudd (WGS84) instead of x and y (note that Lat is</span>
0011 <span class="comment">%    the first argument).</span>
0012 <span class="comment">%    If you need to convert from UTM to Lat/Lon you may use utm2deg.m also</span>
0013 <span class="comment">%    available at Matlab Central</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% Arguments:</span>
0016 <span class="comment">%    filename Example 'rafael', will become 'rafael.kmz'.  The same name</span>
0017 <span class="comment">%             will appear inside Temporary Places in Google Earth as a layer.</span>
0018 <span class="comment">%    dot_size Approximate size of the mark, in meters</span>
0019 <span class="comment">%    Lat, Lon Vectors containing Latitudes and Longitudes.  The number of marks</span>
0020 <span class="comment">%             created by this function is equal to the length of Lat/Lon vectors</span>
0021 <span class="comment">%(opt)style   allows for specifying symbols and colors (line styles are not</span>
0022 <span class="comment">%             supported by Google Earth currently. (see bellow)</span>
0023 <span class="comment">%(opt)opt...   allows for specifying symbol size and line width (see bellow)</span>
0024 <span class="comment">%</span>
0025 <span class="comment">% Example:</span>
0026 <span class="comment">%    GEplot('my_track',Lat,Lon,'o-r','MarkerSize',10,'LineWidth',3)</span>
0027 <span class="comment">%    GEplot('my_track',Lat,Lon)</span>
0028 <span class="comment">%</span>
0029 <span class="comment">% Plot style parameters implemented in GEplot</span>
0030 <span class="comment">%            color               symbol                line style</span>
0031 <span class="comment">%            -----------------------------------------------------------</span>
0032 <span class="comment">%            b     blue          .     point              -    solid</span>
0033 <span class="comment">%            g     green         o     circle          (none)  no line</span>
0034 <span class="comment">%            r     red           x     x-mark</span>
0035 <span class="comment">%            c     cyan          +     plus</span>
0036 <span class="comment">%            m     magenta       *     star</span>
0037 <span class="comment">%            y     yellow        s     square</span>
0038 <span class="comment">%            k     black         d     diamond</span>
0039 <span class="comment">%            w     white (new)   S     filled square (new)</span>
0040 <span class="comment">%                                D     filled diamond (new)</span>
0041 <span class="comment">%                                O     filled circle=big dot (new)</span>
0042 <span class="comment">%</span>
0043 <span class="comment">% Plot properties: 'MarkerSize' 'LineWidth'</span>
0044 <span class="comment">%</span>
0045 <span class="comment">% Additional Notes:</span>
0046 <span class="comment">% 'Hold on' and 'Hold off' were not implemented since one can generate a</span>
0047 <span class="comment">%    .kmz file for each plot and open all simultaneously within GE.</span>
0048 <span class="comment">% Unless you have a lot of data point it is recomended to show the symbols</span>
0049 <span class="comment">%    since they are created in a separate folder so within Google Earth it</span>
0050 <span class="comment">%    is very easy to show/hide the line or the symbols.</span>
0051 <span class="comment">% Current kml/kmz format does not support different linestyles, just solid.</span>
0052 <span class="comment">%    Nevertheless it is possible to define the opacity of the color (the</span>
0053 <span class="comment">%    first FF in the color definition means no transparency).</span>
0054 <span class="comment">% Within Matlab, it is possible to generate a second plot with the</span>
0055 <span class="comment">%    same name, then you just need to select File/Revert within GE to update.</span>
0056 <span class="comment">%</span>
0057 <span class="comment">%</span>
0058 <span class="comment">% Author: Rafael Palacios, Universidad Pontificia Comillas</span>
0059 <span class="comment">% http://www.iit.upcomillas.es/palacios</span>
0060 <span class="comment">% November 2006</span>
0061 <span class="comment">% Version 1.1: Fixed an error while plotting graphs without symbols.</span>
0062 <span class="comment">%</span>
0063 
0064 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0065 <span class="comment">% Argument checking</span>
0066 <span class="comment">%</span>
0067 error(nargchk(4, 9, nargin));  <span class="comment">%3 arguments required, 8 maximum</span>
0068 n1=length(Lat);
0069 n2=length(Lon);
0070 n3=length(Elev);
0071 <span class="keyword">if</span> (n1~=n2 | n1~=n3)
0072    error(<span class="string">'Lat, Lon, and Elev vectors should have the same length'</span>);
0073 <span class="keyword">end</span>
0074 <span class="keyword">if</span> (nargin==6 || nargin==8)
0075     error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0076 <span class="keyword">end</span>
0077 
0078 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0079 <span class="comment">% symbol size and line width</span>
0080 <span class="comment">%</span>
0081 markersize=7; <span class="comment">%matlab default</span>
0082 linewidth=2;  <span class="comment">%matlab default is 0.5, too thin for map overlay</span>
0083 <span class="keyword">if</span> (nargin==7)
0084     <span class="keyword">if</span> (strcmpi(opt11,<span class="string">'markersize'</span>)==1)
0085         markersize=opt12;
0086     <span class="keyword">elseif</span> (strcmpi(opt11,<span class="string">'linewidth'</span>)==1)
0087         linewidth=opt12;
0088     <span class="keyword">else</span>
0089         error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0090     <span class="keyword">end</span>
0091 <span class="keyword">end</span>
0092 <span class="keyword">if</span> (nargin==9)
0093     <span class="keyword">if</span> (strcmpi(opt21,<span class="string">'markersize'</span>)==1)
0094         markersize=opt22;
0095     <span class="keyword">elseif</span> (strcmpi(opt21,<span class="string">'linewidth'</span>)==1)
0096         linewidth=opt22;
0097     <span class="keyword">else</span>
0098         error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0099     <span class="keyword">end</span>
0100 <span class="keyword">end</span>
0101        
0102 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0103 <span class="comment">% symbol, line style and color</span>
0104 <span class="comment">%</span>
0105 symbol=<span class="string">'none'</span>;
0106 iconfilename=<span class="string">'none'</span>;
0107 linestyle=<span class="string">'-'</span>;
0108 color=<span class="string">'b'</span>;
0109 colorstring=<span class="string">'7fff0000'</span>;
0110 
0111 <span class="keyword">if</span> (nargin&gt;=5)
0112     <span class="comment">%linestyle</span>
0113     <span class="keyword">if</span> (strfind(style,<span class="string">'-'</span>))
0114         linestyle=<span class="string">'-'</span>;
0115     <span class="keyword">else</span>
0116         linestyle=<span class="string">'none'</span>;
0117     <span class="keyword">end</span>
0118 
0119     <span class="comment">%symbol</span>
0120     <span class="keyword">if</span> (strfind(style,<span class="string">'.'</span>)), symbol=<span class="string">'.'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0121     <span class="keyword">if</span> (strfind(style,<span class="string">'o'</span>)), symbol=<span class="string">'o'</span>; iconfilename=<span class="string">'circle'</span>; <span class="keyword">end</span>
0122     <span class="keyword">if</span> (strfind(style,<span class="string">'x'</span>)), symbol=<span class="string">'x'</span>; iconfilename=<span class="string">'x'</span>; <span class="keyword">end</span>
0123     <span class="keyword">if</span> (strfind(style,<span class="string">'+'</span>)), symbol=<span class="string">'+'</span>; iconfilename=<span class="string">'plus'</span>; <span class="keyword">end</span>
0124     <span class="keyword">if</span> (strfind(style,<span class="string">'*'</span>)), symbol=<span class="string">'*'</span>; iconfilename=<span class="string">'star'</span>; <span class="keyword">end</span>
0125     <span class="keyword">if</span> (strfind(style,<span class="string">'s'</span>)), symbol=<span class="string">'s'</span>; iconfilename=<span class="string">'square'</span>; <span class="keyword">end</span>
0126     <span class="keyword">if</span> (strfind(style,<span class="string">'d'</span>)), symbol=<span class="string">'d'</span>; iconfilename=<span class="string">'diamond'</span>; <span class="keyword">end</span>
0127     <span class="keyword">if</span> (strfind(style,<span class="string">'S'</span>)), symbol=<span class="string">'S'</span>; iconfilename=<span class="string">'Ssquare'</span>; <span class="keyword">end</span>
0128     <span class="keyword">if</span> (strfind(style,<span class="string">'D'</span>)), symbol=<span class="string">'D'</span>; iconfilename=<span class="string">'Sdiamon'</span>; <span class="keyword">end</span>
0129     <span class="keyword">if</span> (strfind(style,<span class="string">'O'</span>)), symbol=<span class="string">'O'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0130     <span class="keyword">if</span> (strfind(style,<span class="string">'0'</span>)), symbol=<span class="string">'O'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0131 
0132     <span class="comment">%color</span>
0133     <span class="keyword">if</span> (strfind(style,<span class="string">'b'</span>)), color=<span class="string">'b'</span>; colorstring=<span class="string">'7fff0000'</span>; <span class="keyword">end</span>
0134     <span class="keyword">if</span> (strfind(style,<span class="string">'g'</span>)), color=<span class="string">'g'</span>; colorstring=<span class="string">'7f00ff00'</span>; <span class="keyword">end</span>
0135     <span class="keyword">if</span> (strfind(style,<span class="string">'r'</span>)), color=<span class="string">'r'</span>; colorstring=<span class="string">'7f0000ff'</span>; <span class="keyword">end</span>
0136     <span class="keyword">if</span> (strfind(style,<span class="string">'c'</span>)), color=<span class="string">'c'</span>; colorstring=<span class="string">'7fffff00'</span>; <span class="keyword">end</span>
0137     <span class="keyword">if</span> (strfind(style,<span class="string">'m'</span>)), color=<span class="string">'m'</span>; colorstring=<span class="string">'7fff00ff'</span>; <span class="keyword">end</span>
0138     <span class="keyword">if</span> (strfind(style,<span class="string">'y'</span>)), color=<span class="string">'y'</span>; colorstring=<span class="string">'7f00ffff'</span>; <span class="keyword">end</span>
0139     <span class="keyword">if</span> (strfind(style,<span class="string">'k'</span>)), color=<span class="string">'k'</span>; colorstring=<span class="string">'7f000000'</span>; <span class="keyword">end</span>
0140     <span class="keyword">if</span> (strfind(style,<span class="string">'w'</span>)), color=<span class="string">'w'</span>; colorstring=<span class="string">'7fffffff'</span>; <span class="keyword">end</span>
0141 <span class="keyword">end</span>
0142 
0143 iconfilename=strcat(<span class="string">'GEimages/'</span>,iconfilename,<span class="string">'_'</span>,color,<span class="string">'.png'</span>);
0144 <span class="keyword">if</span> (symbol==<span class="string">'.'</span>) 
0145     markersize=markersize/5;
0146 <span class="keyword">end</span>
0147 
0148 
0149 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0150 <span class="comment">% Creating kml file</span>
0151 <span class="comment">%</span>
0152 fp=fopen(strcat(filename,<span class="string">'.kml'</span>),<span class="string">'w'</span>);
0153 <span class="keyword">if</span> (fp==-1)
0154     message=disp(<span class="string">'Unable to open file %s.kml'</span>,filename);
0155     error(message);
0156 <span class="keyword">end</span>
0157 fprintf(fp,<span class="string">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n'</span>);
0158 fprintf(fp,<span class="string">'&lt;kml xmlns=&quot;http://earth.google.com/kml/2.1&quot;&gt;\n'</span>);
0159 fprintf(fp,<span class="string">'&lt;Document&gt;\n'</span>);
0160 fprintf(fp,<span class="string">'&lt;name&gt;%s&lt;/name&gt;\n'</span>,strcat(filename,<span class="string">'.kml'</span>));
0161 fprintf(fp,<span class="string">'&lt;description&gt;Graph generated in Matlab (using GEplot.m by Rafael Palacios)&lt;/description&gt;\n'</span>);
0162 <span class="comment">%</span>
0163 <span class="comment">%Symbol styles definition</span>
0164 fprintf(fp,<span class="string">'&lt;Style id=&quot;mystyle&quot;&gt;\n'</span>);
0165 fprintf(fp,<span class="string">'   &lt;IconStyle&gt;\n'</span>);
0166 fprintf(fp,<span class="string">'      &lt;scale&gt;%.2f&lt;/scale&gt;\n'</span>,markersize/14); <span class="comment">%scale adjusted for .png image sizes</span>
0167 fprintf(fp,<span class="string">'      &lt;Icon&gt;&lt;href&gt;%s&lt;/href&gt;&lt;/Icon&gt;\n'</span>,iconfilename);
0168 fprintf(fp,<span class="string">'   &lt;/IconStyle&gt;\n'</span>);
0169 fprintf(fp,<span class="string">'   &lt;LineStyle&gt;\n'</span>);
0170 fprintf(fp,<span class="string">'      &lt;color&gt;%s&lt;/color&gt;\n'</span>,colorstring);
0171 fprintf(fp,<span class="string">'      &lt;width&gt;%d&lt;/width&gt;\n'</span>,linewidth);
0172 fprintf(fp,<span class="string">'   &lt;/LineStyle&gt;\n'</span>);
0173 fprintf(fp,<span class="string">'   &lt;PolyStyle&gt;\n'</span>);
0174 fprintf(fp,<span class="string">'      &lt;color&gt;7fffffff&lt;/color&gt;\n'</span>);            
0175 fprintf(fp,<span class="string">'      &lt;colorMode&gt;normal&lt;/colorMode&gt;\n'</span>);      
0176 fprintf(fp,<span class="string">'      &lt;fill&gt;1&lt;/fill&gt;\n'</span>);                     
0177 fprintf(fp,<span class="string">'      &lt;outline&gt;1&lt;/outline&gt;\n'</span>);              
0178 fprintf(fp,<span class="string">'   &lt;/PolyStyle&gt;\n'</span>);
0179 fprintf(fp,<span class="string">'&lt;/Style&gt;\n'</span>);
0180 fprintf(fp,<span class="string">'\n'</span>);
0181 
0182 
0183 <span class="keyword">if</span> (linestyle==<span class="string">'-'</span>)
0184     fprintf(fp,<span class="string">'    &lt;Placemark&gt;\n'</span>);
0185     fprintf(fp,<span class="string">'      &lt;description&gt;&lt;![CDATA[Line Cross Section created with VMT using GEplot.m]]&gt;&lt;/description&gt;\n'</span>);  
0186     fprintf(fp,<span class="string">'      &lt;name&gt;Line&lt;/name&gt;\n'</span>);
0187     fprintf(fp,<span class="string">'      &lt;visibility&gt;1&lt;/visibility&gt;\n'</span>);
0188     fprintf(fp,<span class="string">'      &lt;open&gt;1&lt;/open&gt;\n'</span>);
0189     fprintf(fp,<span class="string">'      &lt;styleUrl&gt;mystyle&lt;/styleUrl&gt;\n'</span>);
0190     fprintf(fp,<span class="string">'      &lt;LineString&gt;\n'</span>);
0191     fprintf(fp,<span class="string">'        &lt;extrude&gt;1&lt;/extrude&gt;\n'</span>);
0192     fprintf(fp,<span class="string">'        &lt;tessellate&gt;1&lt;/tessellate&gt;\n'</span>);
0193     fprintf(fp,<span class="string">'        &lt;altitudeMode&gt;relativeToGround&lt;/altitudeMode&gt;\n'</span>);
0194     fprintf(fp,<span class="string">'        &lt;coordinates&gt;\n'</span>);
0195     <span class="keyword">for</span> k=1:n1
0196       fprintf(fp,<span class="string">'%.6f,%.6f,%07.2f\n'</span>,Lon(k),Lat(k),Elev(k)); <span class="comment">%max(Elev)-</span>
0197     <span class="keyword">end</span>
0198     fprintf(fp,<span class="string">'        &lt;/coordinates&gt;\n'</span>);
0199     fprintf(fp,<span class="string">'      &lt;/LineString&gt;\n'</span>);
0200     fprintf(fp,<span class="string">'    &lt;/Placemark&gt;\n'</span>);
0201 <span class="keyword">end</span>
0202 
0203 <span class="keyword">if</span> (strcmp(symbol,<span class="string">'none'</span>)==0)
0204 fprintf(fp,<span class="string">'    &lt;Folder&gt;\n'</span>);
0205 fprintf(fp,<span class="string">'      &lt;name&gt;Data points&lt;/name&gt;\n'</span>);
0206 <span class="keyword">for</span> k=1:n1
0207     fprintf(fp,<span class="string">'      &lt;Placemark&gt;\n'</span>);
0208     fprintf(fp,<span class="string">'         &lt;description&gt;&lt;![CDATA[Point created with Matlab GEplot.m]]&gt;&lt;/description&gt;\n'</span>);
0209 <span class="comment">%    fprintf(fp,'         &lt;name&gt;Point %d&lt;/name&gt;\n',k);  %you may add point labels here</span>
0210     fprintf(fp,<span class="string">'         &lt;visibility&gt;1&lt;/visibility&gt;\n'</span>);
0211     fprintf(fp,<span class="string">'         &lt;open&gt;1&lt;/open&gt;\n'</span>);
0212     fprintf(fp,<span class="string">'         &lt;styleUrl&gt;#mystyle&lt;/styleUrl&gt;\n'</span>);
0213     fprintf(fp,<span class="string">'         &lt;Point&gt;\n'</span>);
0214     fprintf(fp,<span class="string">'           &lt;coordinates&gt;\n'</span>);
0215     fprintf(fp,<span class="string">'%.6f,%.6f,%07.2f\n'</span>,Lon(k),Lat(k),Elev(k)); <span class="comment">%max(Elev)-</span>
0216     fprintf(fp,<span class="string">'           &lt;/coordinates&gt;\n'</span>);
0217     fprintf(fp,<span class="string">'         &lt;/Point&gt;\n'</span>);
0218     fprintf(fp,<span class="string">'      &lt;/Placemark&gt;\n'</span>);
0219 <span class="keyword">end</span>
0220 fprintf(fp,<span class="string">'    &lt;/Folder&gt;\n'</span>);
0221 <span class="keyword">end</span>
0222 
0223 fprintf(fp,<span class="string">'&lt;/Document&gt;\n'</span>);
0224 fprintf(fp,<span class="string">'&lt;/kml&gt;\n'</span>);
0225 
0226 fclose(fp);
0227 
0228 <span class="keyword">if</span> (strcmp(symbol,<span class="string">'none'</span>)==1)
0229    zip(filename,{strcat(filename,<span class="string">'.kml'</span>)});
0230 <span class="keyword">else</span>
0231    zip(filename,{strcat(filename,<span class="string">'.kml'</span>), iconfilename});
0232 <span class="keyword">end</span>
0233 movefile(strcat(filename,<span class="string">'.zip'</span>),strcat(filename,<span class="string">'.kmz'</span>));
0234 delete(strcat(filename,<span class="string">'.kml'</span>));</pre></div>
<hr><address>Generated on Tue 30-Apr-2013 10:18:12 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>